#ifndef RateController_HH
#define RateController_HH 1

#include "component.hh"
#include "config.h"
#include <xercesc/dom/DOM.hpp>
#include "routing/routing.hh"
#include "routing/sprouting.hh"
#include "messenger/messenger-event.hh"

#ifdef LOG4CXX_ENABLED
#include <boost/format.hpp>
#include "log4cxx/logger.h"
#else
#include "vlog.hh"
#endif

namespace vigil
{
	using namespace vigil::container;

	static Vlog_module lg("hoolock");

	struct streq {
		bool operator()(string s1, string s2) const
		{
			return (s1 == s2);
		}
	};

	struct strhash {
		size_t operator()(const string& s) const
		{
			HASH_NAMESPACE::hash<const char*> h;
			return h(s.c_str());
		}
	};

	typedef struct {
		//Tcp_socket *sock;	// mostly not required, but needs to be verified
		vector<Routing_module::RoutePtr> routes;
		vector<Flow> flows;
	} route_data;
	typedef hash_map<string, route_data, strhash, streq> route_db;

	/** \brief
	 * 
	 * @author
	 * @date
	 */
	class RateController
		: public container::Component 
	{
		public:
			/** Constructor.
			 * @param c context as required by Component
			 * @param node Xercesc DOMNode
			 */
			RateController(const Context* c, const xercesc::DOMNode*)
				: Component(c) 
			{}

			/** Configure component
			 * Register events.
			 * @param config configuration
			 */
			void configure(const Configuration* config) 
			{ }

			/** Start component.
			 */
			void install() 
			{}

			/** Get instance.
			 * @param ctxt context
			 * @param component reference to RateController
			 */
			static void getInstance(const container::Context*, RateController*& component);
			Disposition handle_flow_in(const Event& e);


			route_db db;
			bool add_db(string mac, Routing_module::RoutePtr rptr, Flow& flow);


		private:
	};
}
#endif
